<?php
include '../../auth/ceklogin.php';
include '../../sql/conn.php';

$barcode=$_REQUEST['barcode'];
$namaBarang=$_REQUEST['namaBarang'];
$idKategoriBarang=$_REQUEST['idKategoriBarang'];
$idSatuanBarang=$_REQUEST['idSatuanBarang'];
$jumBarang=$_REQUEST['jumBarang'];
$hargaJual=$_REQUEST['hargaJual'];
$idSupplier=$_REQUEST['idSupplier'];

$queryi=mysql_query("SELECT idBarang FROM `barang` order by idBarang DESC limit 0,1");
$row=mysql_fetch_array($queryi);
$row=$row[0]+1;
$query=mysql_query("
    INSERT INTO `barang` (
        `idBarang`
        ,`namaBarang`
        ,`idKategoriBarang`
        ,`idSatuanBarang`
        ,`jumBarang`
        ,`hargaJual`
        ,`last_update`
        ,`idSupplier`
        ,`username`
        ,`barcode`)
    VALUES 
    (
        $row
        , '$namaBarang'
        , '$idKategoriBarang'
        , '$idSatuanBarang'
        , '$jumBarang'
        , '$hargaJual'
        , date_format(now(),\"%Y-%m-%d\")
        , '$idSupplier'
        , '$_SESSION[userbkknt]'
        , '$barcode'
    );
");
if($query){
    echo json_encode(array('success'=>true));
} else {
    echo json_encode(array('msg'=>'Error Occured.'.  mysql_error()));
}
?>